package com.itheima.day17.annotation.test1;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        // 1.获取Class对象
        Class className = Class.forName("com.itheima.day17.annotation.test1.UserTest");

        // 2.创建对象
        UserTest user = (UserTest) className.newInstance();

        // 3.获得所有Method对象
        Method[] declaredMethods = className.getDeclaredMethods();

        // 4.遍历Method对象集合
        for (Method method : declaredMethods) {
            // boolean isAnnotationPresent​(Class<? extends Annotation> annotationClass) 如果此元素上 存在指定类型的注释，则返回true，否则返回false。
            if(method.isAnnotationPresent(Test.class)){
                method.setAccessible(true);
                method.invoke(user);
            }

        }

    }
}
